<script>
	export default {
		onLaunch: function() {
			var code = this.getcode('code')
			console.log(code)
			var url=window.location.protocol + "//" +  window.location.host + window.location.pathname + this.urlencode(window.location.hash+ window.location.search)
			console.log(url);
			if (code==''||code==null) {
				window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + 'wx7196e37b78f6199d' + '&redirect_uri=' + url + '&response_type=code&scope=snsapi_userinfo&state=cell#wechat_redirect'
			}
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			getcode(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if (r != null) return unescape(r[2]);
				return null;
			},
			urlencode(str) {
				str = (str + '').toString();
				return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').
				replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
	.login-styless .u-form-item--left{
		background-color: #F5FAFF !important;
		padding-left: 10upx;
	}
	.no-back .u-form-item--left{
		background-color: #fff !important;
		padding-left: 10upx;
	}
</style>
